#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#ifdef HPUX
#include <sys/pstat.h>
#endif
#include <errno.h>

#ifdef HPUX
unsigned long mb_free(void)
{
static struct pst_vminfo pd2;
int x;
	x=pstat_getvminfo(&pd2,sizeof(struct pst_vminfo),(size_t)1,0);
	if(x==1) {
		return((unsigned long)(pd2.psv_cfree/256)); /* 4kb pages - so /256 = Mb */
	}
	return(-1);
}
#endif

int main(int argc,char **argv)
{
	unsigned long x=mb_free();
	if(x==-1) {
		fprintf(stderr,"Error: Unable to get free memory.\n");
		exit(1);
	} else {
		printf("%ld\n",x);
		exit(0);
	}
}

